<template>
    <div>
        <base-list ref="jobMachinery" :condition="condition" :datas.sync="jobMachinery" :pageSearch="pageSearch">
            <el-form :inline="true" :model="condition" class="search-form" slot="search" label-width="80px">
                <el-row>
                    <el-col :span="7" class="search-width4">
                        <el-form-item label="机械名称">
                            <!--<el-input v-model="condition['search_LIKE_resourceName']"></el-input>-->
                            <auto-search-resource searchType="JOB_JX" searchName="resourceName" @selectName="v=>condition['search_LIKE_resourceName']=v"></auto-search-resource>
                        </el-form-item>
                    </el-col>
                    <el-col :span="7" class="search-width4">
                        <el-form-item label="机械类型">
                            <auto-search-dic @selectName="v=>condition['search_LIKE_typeName']=v"
                                             :name="condition['search_LIKE_typeName']"
                                             code="JOB_JXLX"></auto-search-dic>
                        </el-form-item>
                    </el-col>
                    <el-col :span="7" class="search-width4">
                        <el-form-item label="机械类别">
                            <auto-search-dic @selectName="v=>condition['search_LIKE_categoryName']=v"
                                             :name="condition['search_LIKE_categoryName']"
                                             code="JOB_JXLB"></auto-search-dic>
                        </el-form-item>
                    </el-col>
                <!-- </el-row>
                <el-row>   -->
                    <el-col :span="5" class="search-width4">
                        <el-form-item label="是否可用">
                            <el-select v-model="condition['search_EQ_valid']" placeholder="请选择" clearable>
                                <el-option v-for="[key, val] in _dictTrueOrFalse" :key="key" :label="val"
                                           :value="key"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="2">
                        <el-button type="primary" icon="el-icon-search" @click="loadData" class="ml-80">查 询</el-button>
                    </el-col>
                </el-row>
            </el-form>
            <el-row slot="status">
                <el-col :span="24">
                    <el-button type="primary" formVisible="true" icon="el-icon-plus" @click="handleDialogFormOpen(false)" v-if="power('WJOB_BASEMGR_MACHINE:ADD')">
                            新增
                        </el-button>
                </el-col>
            </el-row>
            <el-table slot="list" :data="jobMachinery" border stripe max-height="550">
                <el-table-column prop="resourceName" label="机械名称"  min-width="130"></el-table-column>
                <el-table-column prop="typeName" label="机械类型"  min-width="130"></el-table-column>
                <el-table-column prop="categoryName" label="机械类别"  min-width="120"></el-table-column>
                <el-table-column prop="terminalName" label="使用终端"  min-width="120"></el-table-column>
                <el-table-column prop="orgName" label="所属单位"  min-width="200"></el-table-column>
                <el-table-column prop="deptName" label="所属部门"  min-width="200"></el-table-column>
                <el-table-column prop="valid" label="是否可用"  min-width="120">
                    <template slot-scope="scope">
                        {{ scope.row.valid | _filterTrueOrFalse }}
                    </template>
                </el-table-column>
                <el-table-column prop="wharf" label="码头机械"  min-width="120">
                    <template slot-scope="scope">
                        {{ scope.row.wharf | _filterTrueOrFalse }}
                    </template>
                </el-table-column>
                <el-table-column prop="yard" label="堆场机械"  min-width="120">
                    <template slot-scope="scope">
                        {{ scope.row.yard | _filterTrueOrFalse }}
                    </template>
                </el-table-column>
                <el-table-column prop="warehouse" label="仓库机械"  min-width="120">
                    <template slot-scope="scope">
                        {{ scope.row.warehouse | _filterTrueOrFalse }}
                    </template>
                </el-table-column>
                <el-table-column prop="others" label="其它机械"  min-width="120">
                    <template slot-scope="scope">
                        {{ scope.row.others | _filterTrueOrFalse }}
                    </template>
                </el-table-column>
                <el-table-column prop="resourceDescribe" label="备注"  min-width="200"></el-table-column>
                <el-table-column fixed="right" align="center" label="操作"  width="140">
                    <template slot-scope="scope">
                        <!-- v-if="power('WJOB_BASEMGR_MACHINE:UPD')" -->
                        <el-button size="small" type="text" @click="handleDialogFormOpen(true,scope.row)">
                            编辑
                        </el-button>
                        <!-- v-if="power('WJOB_BASEMGR_MACHINE:DEL')" -->
                        <el-button type="text" class="danger" size="small" @click="handleRemove(scope.row)">删除
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
        </base-list>
        <job-machinery-form ref="jobMachineryForm" @load="loadData"></job-machinery-form>
    </div>
</template>

<script>
    import { deleteJobMachinery, getJobMachineryList } from "@/api/baseResource/baseResource"
    import autoSearchOrg from '@/components/autocomplete/autoSearchOrg'
    import autoSearchDic from '@/components/autocomplete/autoSearchDic'
    import autoSearchResource from '@/components/autocomplete/autoSearchResource'
    import jobMachineryForm from './jobMachineryForm'

    export default {
        name: "jobMachinery",
        components: {
            jobMachineryForm,
            autoSearchOrg,
            autoSearchDic,
            autoSearchResource
        },
        data() {
            return {
                condition: {}, // 查询条件
                jobMachinery: [], // table数组
                pageSearch: getJobMachineryList, // 分页查询api接口
                id: ''
            }
        },
        mounted() {
            this.$nextTick(() => {
                this.loadData()
            })
        },
        methods: {
            loadData() {
                this.$refs.jobMachinery.loadData()
            },
            handleDialogFormOpen(bool, item) {
                if (bool) {
                    let form = JSON.parse(JSON.stringify(item))
                    this.$refs.jobMachineryForm.form = {
                        id:form.id,
                        resourceName:form.resourceName,
                        typeId:form.typeId,
                        typeName:form.typeName,
                        typeCode:form.typeCode,
                        categoryId:form.categoryId,
                        categoryName:form.categoryName,
                        categoryCode:form.categoryCode,
                        orgId:form.orgId,
                        orgName:form.orgName,
                        deptId:form.deptId,
                        deptName:form.deptName,
                        terminalId:form.terminalId,
                        terminalName:form.terminalName,
                        valid:form.valid,
                        wharf:form.wharf,
                        yard:form.yard,
                        warehouse:form.warehouse,
                        others:form.others,
                        resourceDescribe:form.resourceDescribe,
                    }
                    this.$refs.jobMachineryForm.isEdit = true
                    this.$refs.jobMachineryForm.dialogForm = true
                } else {
                    this.$refs.jobMachineryForm.dialogForm = true
                }
            },
            handleRemove(item) {
                this.$confirm(`是否删除该数据?`, '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    deleteJobMachinery(item.id).then(res => {
                        this.$message({
                            type: 'success',
                            message: `删除成功!`
                        });
                        this.loadData()
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消'
                    });
                });
            }
        },
    }

</script>

<style scoped>


</style>
